package com.fanrenqiji.modules.sys.dao;

import com.fanrenqiji.common.persistence.BaseDao;
import com.fanrenqiji.common.persistence.BaseDaoImpl;
import com.fanrenqiji.modules.sys.entity.Office;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Set;

/**
 * @author lijian E-mail:ljz0721cx@163.com
 * @version 创建时间：2015年1月26日 下午3:08:37
 * @description 用于组织及机构的通路的控制
 */

public interface OfficeDao extends OfficeDaoCustom,
		CrudRepository<Office, Long> {

	@Modifying
	@Query("update Office set delFlag='" + Office.DEL_FLAG_DELETE
			+ "' where id = ?1 or parentIds like ?2")
	public int deleteById(Long id, String likeParentIds);

	public List<Office> findByParentIdsLike(String parentIds);

	public Set<Office> findByParentIdsContaining(String parentIds);

	@Query("from Office where code = ?1 and delFlag = '"
			+ Office.DEL_FLAG_NORMAL + "'")
	public Office findByCode(String code);

	public List<Office> findByGradeAndIsBusiness(String grade, String isBusiness);

	@Query(nativeQuery = true, value = "SELECT grade from sys_office where id =?1 and del_flag = '"+ Office.DEL_FLAG_NORMAL + "'")
	public String getOfficeGradeById(Long officeId);

}

interface OfficeDaoCustom extends BaseDao<Office> {
}

@Repository
class OfficeDaoImpl extends BaseDaoImpl<Office> implements OfficeDaoCustom {

}